<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <style>
      body {
        font-size: 30px;
      }
      .btn {
        padding: 10px 20px;
        font-size: 20px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <m-child class="btn" v-on:m-child-increment="abc"></m-child>
      <m-child class="btn" v-on:m-child-increment="abc"></m-child>
      <m-child class="btn" v-on:m-child-increment="abc"></m-child>
      <div>总共: {{ total }}</div> 
    </div>

    <script>
      Vue.component("m-child", {
        template: '<button v-on:click="increment">{{ counter }}</button>',
        data: function() {
          return {
            counter: 0
          };
        },
        methods: {
          increment: function() {
            this.counter += 1;
            //触发自定义increment1的函数。此处的increment1函数就是 incrementTotal1函数。
            this.$emit("m-child-increment", "这个位子是可以加参数的");
          }
        }
      });
      // 创建根实例
      new Vue({
        el: "#app",
        data: {
          total: 0
        },
        methods: {
          abc: function(e) {
            this.total += 1;
          }
        }
      });
    </script>
  </body>
</html>
